
/****** Object:  StoredProcedure [dbo].[web_ins_upd_klij]    Script Date: 10/19/2013 09:20:36 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'web_ins_upd_card_info')
DROP PROCEDURE web_ins_upd_card_info
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[web_ins_upd_card_info]
	@kortele char(12),
	@nuo char(2),
	@iki char(2),
	@credit char(6),
	@p1 char(1),
	@p2 char(1),
	@p3 char(1),
	@p4 char(1),
	@p5 char(1),
	@p6 char(1),
	@p7 char(1),
	@lustas char(30)
AS
BEGIN
	SET NOCOUNT ON

	If exists(SELECT * FROM n51_suth_c where N51_c_kodas_kt = @kortele)
		update n51_suth_c set 
		N51_c_limitas = CASE WHEN ISNUMERIC(@credit)=1 THEN CAST(@credit as numeric(6,0)) ELSE null END,
		n51_valanda_nuo = @nuo,
		n51_valanda_iki = @iki,
		n51_pirmadienis = CAST(@p1 as numeric(1,0)),		
		n51_antradienis = CAST(@p2 as numeric(1,0)),
		n51_treciadienis = CAST(@p3 as numeric(1,0)),
		n51_ketvirtadienis = CAST(@p4 as numeric(1,0)),
		n51_penktadienis = CAST(@p5 as numeric(1,0)),
		n51_sestadienis = CAST(@p6 as numeric(1,0)),
		n51_sekmadienis = CAST(@p7 as numeric(1,0)),
		n51_lustas = CASE WHEN @lustas is not null THEN @lustas ELSE n51_lustas END
		where N51_c_kodas_kt = @kortele
	else
		insert INto n51_suth_c ([N51_c_kodas_kt]
      ,[N51_c_limitas]
      ,[n51_valanda_nuo]
      ,[n51_valanda_iki]
      ,[n51_pirmadienis]
      ,[n51_antradienis]
      ,[n51_treciadienis]
      ,[n51_ketvirtadienis]
      ,[n51_penktadienis]
      ,[n51_sestadienis]
      ,[n51_sekmadienis],[n51_lustas]) values (@kortele,CASE WHEN ISNUMERIC(@credit)=1 THEN CAST(@credit as numeric(6,0)) ELSE null END,
	  CASE WHEN ISNUMERIC(@nuo)=1 THEN CAST(@nuo as numeric(2,0)) ELSE null END,
	  CASE WHEN ISNUMERIC(@iki)=1 THEN CAST(@iki as numeric(2,0)) ELSE null END,
	  CAST(@p1 as numeric(1,0)),
	  CAST(@p2 as numeric(1,0)),
	  CAST(@p3 as numeric(1,0)),
	  CAST(@p4 as numeric(1,0)),
	  CAST(@p5 as numeric(1,0)),
	  CAST(@p6 as numeric(1,0)),
	  CAST(@p7 as numeric(1,0)),
	  @lustas
	  )

	
    
END

GO



